from itertools import count
        
def triple_gen(limit, a = 3, b = 4, c = 5):
    """ Generates all primitive pythagorean triples with sum < limit. """
    if a + b + c < limit:
        if a <= b: yield (a, b, c)
        else: yield (b, a, c)
        for (x, y, z) in triple_gen(limit, a - 2*b + 2*c, 2*a - b + 2*c, 2*a - 2*b + 3*c):
            yield (x, y, z)
        for (x, y, z) in triple_gen(limit, a + 2*b + 2*c, 2*a + b + 2*c, 2*a + 2*b + 3*c):
            yield (x, y ,z)
        for (x, y, z) in triple_gen(limit, -a + 2*b + 2*c, -2*a +b + 2*c, -2*a + 2*b + 3*c):
            yield (x, y, z)
    
def triple_gen2(limit, a = 3, b = 4, c = 5):
    """ Generates all primitive pythagorean triples with a < limit and b < limit. """
    if a < limit and b < limit:
        if a <= b: yield (a, b, c)
        else: yield (b, a, c)
        for (x, y, z) in triple_gen2(limit, a - 2*b + 2*c, 2*a - b + 2*c, 2*a - 2*b + 3*c):
            yield (x, y, z)
        for (x, y, z) in triple_gen2(limit, a + 2*b + 2*c, 2*a + b + 2*c, 2*a + 2*b + 3*c):
            yield (x, y ,z)
        for (x, y, z) in triple_gen2(limit, -a + 2*b + 2*c, -2*a +b + 2*c, -2*a + 2*b + 3*c):
            yield (x, y, z)
    
